package org.xm.sk.dao;

import java.util.Set;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.xm.sk.vo.ob.HairdresserSelfInfo;
import org.xm.sk.vo.tb.Hairdresser;

@Repository
public interface HairdresserRepository
        extends JpaRepository<Hairdresser, Integer>,
        JpaSpecificationExecutor<Hairdresser>,
        QuerydslPredicateExecutor<Hairdresser> {

    Set<Hairdresser> findByName(String name);

    @Modifying
    @Query("UPDATE FROM Hairdresser u SET u.datalevel = 2, u.editer = :userid, u.editerName = :username WHERE u.id = :id")
    void delete(@Param("id") int id, @Param("userid") int userid,
            @Param("username") String username);

    @Modifying
    @Query("UPDATE FROM Hairdresser u SET u.datalevel = 2, u.editer = :userid, u.editerName = :username WHERE u.id in :ids")
    void delete(@Param("ids") Set<Integer> ids, @Param("userid") int userid,
            @Param("username") String username);

    Page<Hairdresser> listByLocal(Pageable arg0, Double longitude,
            Double latitude, Double range);

    Page<Hairdresser> listByNameWithLocal(Pageable arg0, Double longitude,
            Double latitude, Double range, String keyStr);

    HairdresserSelfInfo self(int id);

    Page<HairdresserSelfInfo> atList(Pageable arg0, int id);

}
